<?php

require_once APP_PATH . '/../vendor/autoload.php';

//
function encrypt_sm2($str, $publickey)
{
    $sm2 = new \Rtgm\sm\RtSm2();
    $m2EncryptData = $sm2 ->doEncrypt($str, $publickey);
    return $m2EncryptData;
}

function decrypt_sm2($m2EncryptData, $privatekey)
{
    $sm2 = new \Rtgm\sm\RtSm2();
    $m2DecryptData = $sm2 ->doDecrypt($m2EncryptData, $privatekey);
    return $m2DecryptData;
}

function sign_sm2($document, $privatekey)
{
    $sm2 = new \Rtgm\sm\RtSm2('base64');
    return $sm2 ->doSign($document, $privatekey);
}

function verify_sign_sm2($document, $sign, $publickey)
{
    $sm2 = new \Rtgm\sm\RtSm2('base64');
    return $sm2 ->verifySign($document, $sign, $publickey);
}

